
#ifndef B2D_MAP_H
#define B2D_MAP_H
//struct

#include "b2d_common.h"
#include "Box2D.h"
#include <vector>


#define RETURN_VEC_M2P(ARG_COUNT,ARG_VALUE,PARAM,FUNC) \
		ARG_COUNT = 3;	\
		atom_setsym(ARG_VALUE,gensym(PARAM));	\
		b2Vec2 position = FUNC;	\
		atom_setfloat(ARG_VALUE+1,M2P(position.x));	\
		atom_setfloat(ARG_VALUE+2,M2P(position.y));	\
		return true;	\

#define RETURN_VEC(ARG_COUNT,ARG_VALUE,PARAM,FUNC) \
		ARG_COUNT = 3;	\
		atom_setsym(ARG_VALUE,gensym(PARAM));	\
		b2Vec2 position = FUNC;	\
		atom_setfloat(ARG_VALUE+1,(position.x));	\
		atom_setfloat(ARG_VALUE+2,(position.y));	\
		return true;	\

#define RETURN_FLOAT_M2P(ARG_COUNT,ARG_VALUE,PARAM,FUNC) \
		ARG_COUNT = 2;	\
		atom_setsym(ARG_VALUE,gensym(PARAM));	\
		atom_setfloat(ARG_VALUE+1,M2P(FUNC));	\
		return true;	\

#define RETURN_FLOAT(ARG_COUNT,ARG_VALUE,PARAM,FUNC) \
		ARG_COUNT = 2;	\
		atom_setsym(ARG_VALUE,gensym(PARAM));	\
		atom_setfloat(ARG_VALUE+1,FUNC);	\
		return true;	\

#define RETURN_LONG(ARG_COUNT,ARG_VALUE,PARAM,FUNC) \
		ARG_COUNT = 2;	\
		atom_setsym(ARG_VALUE,gensym(PARAM));	\
		atom_setlong(ARG_VALUE+1,FUNC);	\
		return true;	\

#define RETURN_BOOL(ARG_COUNT,ARG_VALUE,PARAM,FUNC) \
		ARG_COUNT = 2;	\
		atom_setsym(ARG_VALUE,gensym(PARAM));	\
		atom_setlong(ARG_VALUE+1,FUNC ? 1:0);	\
		return true;	\


#define SET_FLOAT_FUNC_P2M(ARG_COUNT,ARG_VALUE,FUNC) \
			if(ARG_COUNT == 1) {	\
				FUNC(P2M(atom_getfloat(ARG_VALUE)));	\
				return true;	\
			} else {	\
				return false;	\
			}	\
			
#define SET_FLOAT_FUNC(ARG_COUNT,ARG_VALUE,FUNC) \
			if(ARG_COUNT == 1) {	\
				FUNC(atom_getfloat(ARG_VALUE));	\
				return true;	\
			} else {	\
				return false;	\
			}	\


#define SET_FLOAT(ARG_COUNT,ARG_VALUE,DST) \
			if(ARG_COUNT == 1) {	\
				DST = atom_getfloat(ARG_VALUE);	\
				return true;	\
			} else {	\
				return false;	\
			}	\





#define SET_FLOAT_P2M(ARG_COUNT,ARG_VALUE,DST) \
			if(ARG_COUNT == 1) {	\
				DST = P2M(atom_getfloat(ARG_VALUE));	\
				return true;	\
			} else {	\
				return false;	\
			}	\

#define SET_FLOAT(ARG_COUNT,ARG_VALUE,DST) \
			if(ARG_COUNT == 1) {	\
				DST = atom_getfloat(ARG_VALUE);	\
				return true;	\
			} else {	\
				return false;	\
			}	\
		

#define SET_LONG(ARG_COUNT,ARG_VALUE,DST) \
			if(ARG_COUNT == 1) {	\
				DST = atom_getlong(ARG_VALUE);	\
				return true;	\
			} else {	\
				return false;	\
			}	\


		
	#define SET_BOOL(ARG_COUNT,ARG_VALUE,DST) \
			if(ARG_COUNT == 1) {	\
				DST = atom_getlong(ARG_VALUE) == 1L ? true : false;	\
				return true;	\
			} else {	\
				return false;	\
			}	\
			
	#define SET_FUNC_BOOL(ARG_COUNT,ARG_VALUE,FUNC) \
			post("ARG_GOUNT = %ld",ARG_COUNT);\
			if(ARG_COUNT == 1) {	\
				FUNC(atom_getlong(ARG_VALUE) == 1L ? true : false);	\
				post("BOOL SET TO %dl", (atom_getlong(ARG_VALUE) == 1L ? true : false));\
				return true;	\
			} else {	\
				return false;	\
			}	\
		
		
		
	#define SET_VEC(ARG_COUNT,ARG_VALUE,DST) \
			if(ARG_COUNT == 2) { \
					DST = b2Vec2(atom_getfloat(ARG_VALUE), atom_getfloat(ARG_VALUE+1)); \
					return true; \
				} else { \
					return false; \
				} \

	#define SET_VEC_P2M(ARG_COUNT,ARG_VALUE,DST) \
			if(ARG_COUNT == 2) { \
					DST = b2Vec2(P2M(atom_getfloat(ARG_VALUE)), P2M(atom_getfloat(ARG_VALUE+1))); \
					return true; \
				} else { \
					return false; \
				} \
				
				
#define SET_VEC_FUNC(ARG_COUNT,ARG_VALUE,FUNC) \
			if(ARG_COUNT == 2) { \
					FUNC(b2Vec2(atom_getfloat(ARG_VALUE), atom_getfloat(ARG_VALUE+1))); \
					return true; \
				} else { \
					return false; \
				} \

#define SET_VEC_FUNC_P2M(ARG_COUNT,ARG_VALUE,FUNC) \
			if(ARG_COUNT == 2) { \
					FUNC(b2Vec2(P2M(atom_getfloat(ARG_VALUE)), P2M(atom_getfloat(ARG_VALUE+1)))); \
					return true; \
				} else { \
					return false; \
				} \


/* get parameters on shapes joints and bodies */
bool getParam(char* param, b2Body* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill

bool getParam(char* param, b2CircleShape* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill
bool getParam(char* param, b2PolygonShape* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill

bool getParam(char* param, b2RevoluteJoint* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill
bool getParam(char* param, b2DistanceJoint* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill
bool getParam(char* param, b2PrismaticJoint* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill
bool getParam(char* param, b2PulleyJoint* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill
bool getParam(char* param, b2GearJoint* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill
bool getParam(char* param, b2MouseJoint* x, long& ac, t_atom* av); // pass param, ac to fill, and av to fill

/* set parameters on shapes, joints, and bodies */
bool setParameter(char* param, b2Body* x, long ac, t_atom* av);

bool setParameter(char* param, b2CircleShape* x, long ac, t_atom* av);
bool setParameter(char* param, b2PolygonShape* x, long ac, t_atom* av);

bool setParameter(char* param, b2RevoluteJoint* x, long ac, t_atom* av);
bool setParameter(char* param, b2DistanceJoint* x, long ac, t_atom* av);
bool setParameter(char* param, b2PrismaticJoint* x, long ac, t_atom* av);
bool setParameter(char* param, b2PulleyJoint* x, long ac, t_atom* av);
bool setParameter(char* param, b2GearJoint* x, long ac, t_atom* av);
bool setParameter(char* param, b2MouseJoint* x, long ac, t_atom* av);

				
/* set parameters on DEFS, from shapes, joints and bodies */
bool setParameter(char* param, b2BodyDef& d, long ac, t_atom* av);

bool setParameter(char* param, b2CircleDef& d, long ac, t_atom* av);
bool setParameter(char* param, b2PolygonDef& d, long ac, t_atom* av, std::vector<b2Vec2>* vertices);

bool setParameter(char* param, b2DistanceJointDef& x, long ac, t_atom* av);
bool setParameter(char* param, b2GearJointDef& x, long ac, t_atom* av);
bool setParameter(char* param, b2MouseJointDef& x, long ac, t_atom* av);
bool setParameter(char* param, b2PrismaticJointDef& x, long ac, t_atom* av);
bool setParameter(char* param, b2PulleyJointDef& x, long ac, t_atom* av);
bool setParameter(char* param, b2RevoluteJointDef& x, long ac, t_atom* av);


#endif		
